import { HttpClient } from '@angular/common/http';
import { Injectable } from '@angular/core';
import { Observable } from "rxjs";

@Injectable({
  providedIn: 'root'
})
export class SellCouponbagHandleService {

  serviceUrls = {
    couponListUrl: '/coupon/', // 优惠券list--URL
    addCouponUrl: '/couponPackage/save', // 添加优惠券包
    editCouponUrl: '/couponPackage/update', // 修改优惠券包
    couponDetailsUrl: '/couponPackage/details', // 查询优惠券卡包详情

    seconeCouponListUrl: '/recycleCoupon/', // 二手优惠券List
    recoveryMarkupListUrl: '/markUpRecycleCouponInfo/' // 回收加价券List'
  };

  constructor(public httpClient: HttpClient) { }

  /**
   * 优惠券列表
   * @param params 
   * @param type 1: 配件 2: 二手 3: 加价 4: 定制
   * @returns 
   */
  getCouponTableData(params: any, type: number) {
    let urlObj: any = {
      1: this.serviceUrls.couponListUrl,
      2: this.serviceUrls.seconeCouponListUrl,
      3: this.serviceUrls.recoveryMarkupListUrl
    }
    return this.httpClient.get(urlObj[type], { params: params }).toPromise();
  }

  // 查询优惠券包详情
  queryCouponDetailData(params: any) {
    return this.httpClient.post(this.serviceUrls.couponDetailsUrl, params).toPromise();
  }

  // 添加优惠券包
  addCouponData(params: any) {
    return this.httpClient.post(this.serviceUrls.addCouponUrl, params).toPromise();
  }
  
  // (修改 || 删除)优惠券包
  editCouponData(params: any) {
    return this.httpClient.post(this.serviceUrls.editCouponUrl, params).toPromise();
  }
}



